package com.huirui.server.controller.admin;

import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.UserVo;
import com.huirui.server.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.time.LocalDate;

@RestController("adminUserController")
@RequestMapping("/admin/user")
@Slf4j
@Validated
@Tag(name = "会员管理", description = "微信小程序会员管理")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/list")
    @Operation(summary = "根据条件查询用户")
    public Result<PageResult<UserVo>> list(
            @RequestParam(value = "userName", required = false) String userName,
            @RequestParam(value = "userId", required = false) Long userId,
            @RequestParam(value = "phoneNumber", required = false) String phoneNumber,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            @RequestParam(value = "registrationStartDate", required = false) LocalDate registrationStartDate,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            @RequestParam(value = "registrationEndDate", required = false) LocalDate registrationEndDate,
            @RequestParam(value = "minimumConsumptionAmount", required = false) BigDecimal minimumConsumptionAmount,
            @RequestParam(value = "maximumConsumptionAmount", required = false) BigDecimal maximumConsumptionAmount,
            @RequestParam(value = "page") Long page,
            @RequestParam(value = "pageSize") Long pageSize
    ) {
        PageResult<UserVo> res = userService
                .listByCondition(
                        userName,
                        userId,
                        phoneNumber,
                        registrationStartDate,
                        registrationEndDate,
                        minimumConsumptionAmount,
                        maximumConsumptionAmount,
                        page,
                        pageSize
                );
        return Result.success(res);
    }

}
